package com.ss.android.article.browser.view.user;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.TextView;

import com.a.a.s;
import com.bytedance.common.utility.UIUtils;
import com.ss.android.article.browser.download.aa.a$a;
import com.ss.android.article.browser.download.DownloadTaskManager;
import com.ss.android.article.browser.download.internal.DownloadTask;
import com.ss.android.article.browser.download.l;
import com.ss.android.article.browser.view.multiselect.f;
import com.ss.android.article.browser.view.user.a.c;
import com.ss.android.common.app.AbsApplication;
import com.ss.android.common.app.AbsFragment;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public final class e extends AbsFragment implements AdapterView.OnItemClickListener, a$a, com.ss.android.article.browser.view.multiselect.d, f, t, u {
    private View a;
    private View b;
    private RecyclerView c;
    private com.ss.android.article.browser.view.multiselect.a d;
    private c e;
    private v f;

    public e() {

    }

    static c a(e arg1) {
        return arg1.e;
    }

    static void a(e arg3, boolean arg4) {
        boolean v1 = false;
        View v2 = arg3.b;
        int v0 = arg4 ? 0 : 8;
        UIUtils.setVisibility(v2, v0);
        if (arg3.f != null) {
            v v0_1 = arg3.f;
            if (!arg4) {
                v1 = true;
            }

            v0_1.b(v1);
        }
    }

    static void a(ArrayList arg3) {
        Iterator v1 = arg3.iterator();
        while (v1.hasNext()) {
            Object v0 = v1.next();
            try {
                DownloadTaskManager.getInstance().d(((DownloadTask) v0));
                DownloadTaskManager.a(((DownloadTask) v0).getFilePath());
            } catch (Exception v0_1) {
            }
        }
    }

    public final void a() {
        if (this.f != null) {
            this.f.b();
        }

        this.g();
    }

    public final void a(int arg4) {
        Intent v1_1;
        if (this.e != null) {
            List<DownloadTask> v0 = this.e.a;
            if (arg4 >= v0.size()) {
                return;
            }

            String v0_1 = v0.get(arg4).getFilePath();
            try {
                v1_1 = android.support.design.a.s(v0_1);
                if (v1_1 == null) {
                } else {
                    AbsApplication.getApplication().startActivity(v1_1);
                }
            } catch (Exception v1) {
            }

            if (com.ss.android.article.browser.download.b.a.b(v0_1)) {
                com.ss.android.article.browser.download.b.a.c(v0_1);
                return;
            }

            try {
                v1_1 = new Intent("android.intent.action.VIEW");
                Uri v0_3 = Uri.fromFile(new File(v0_1));
                v1_1.addCategory("android.intent.category.DEFAULT");
                v1_1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                v1_1.setData(v0_3);
                this.startActivity(v1_1);
            } catch (Exception v0_2) {
            }
        }
    }

    public final void a(DownloadTask arg4) {
        if (arg4 != null) {
            List v0 = this.e.a;
            if (!v0.contains(arg4)) {
                v0.add(0, arg4);
                this.d.notifyItemInserted(0);
            }
        }
    }

    public final void a(boolean arg2) {
        if (arg2) {
            this.d.c();
        } else {
            this.d.e();
        }
    }

    static com.ss.android.article.browser.view.multiselect.a b(e arg1) {
        return arg1.d;
    }

    public final void b() {
        if (this.f != null) {
            this.f.c();
        }
    }

    public final void b(int arg2) {
        if (arg2 >= this.e.getItemCount() && this.f != null) {
            this.f.a();
        }

        this.g();
    }

    static v c(e arg1) {
        return arg1.f;
    }

    public final void c() {
        this.d.a();
        this.g();
    }

    public final void d() {
        s v0 = s.a(new h(this));
        ((com.a.a.e) v0).b = android.support.design.a.c();
        ((com.a.a.e) v0).c = android.support.design.a.b();
        v0.a(new com.ss.android.article.browser.view.user.g(this));
    }

    public final void e() {
        this.d.b();
        this.g();
    }

    public final void f() {
        if (this.f != null) {
            v v1 = this.f;
            boolean v0 = this.b.getVisibility() != View.VISIBLE ? true : false;
            v1.b(v0);
        }
    }

    private void g() {
        if (this.f != null) {
            v v1 = this.f;
            boolean v0 = this.d.f().size() > 0 ? true : false;
            v1.a(v0);
        }
    }

    public final void onActivityCreated(@Nullable Bundle arg3) {
        super.onActivityCreated(arg3);
        s v0 = s.a(new l(DownloadTaskManager.getInstance()));
        ((com.a.a.e) v0).b = android.support.design.a.c();
        ((com.a.a.e) v0).c = android.support.design.a.b();
        v0.a(new com.ss.android.article.browser.view.user.f(this));
    }

    public final void onAttach(Context arg2) {
        super.onAttach(arg2);
        if ((arg2 instanceof v)) {
            this.f = ((v) arg2);
        }
    }

    public final void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        FragmentActivity v0 = this.getActivity();
        if ((v0 instanceof UserActionHistoryActivity)) {
            com.ss.android.article.browser.download.aa v0_1 = ((UserActionHistoryActivity) v0).a;
            if (v0_1 != null) {
                v0_1.b = this;
            }
        }
    }

    @Nullable
    public final View onCreateView(LayoutInflater arg5, @Nullable ViewGroup arg6, @Nullable Bundle arg7) {
        this.a = arg5.inflate(com.ss.android.article.browser.R.layout.ew, arg6, false);
        this.b = this.a.findViewById(com.ss.android.article.browser.R.id.s9);
        ((TextView) this.b.findViewById(com.ss.android.article.browser.R.id.s_)).setText(com.ss.android.article.browser.R.string.ji);
        com.bytedance.frameworks.a.d.a v1 = new com.bytedance.frameworks.a.d.a(this.getContext());
        v1.a = ((int) UIUtils.dp2px(this.getContext(), 1f));
        this.c = this.a.findViewById(com.ss.android.article.browser.R.id.recycler_view);
        v1.a = 1;
        v1.a(this.getResources().getDrawable(com.ss.android.article.browser.R.color.fv));
        this.c.addItemDecoration(((RecyclerView.ItemDecoration) v1));
        com.ss.android.article.browser.view.multiselect.viewholder.a.a v0 = new com.ss.android.article.browser.view.multiselect.viewholder.a.a((byte) 0);
        this.e = new c();
        this.d = com.ss.android.article.browser.view.multiselect.c.a(this.getActivity()).a(this.e).a(this.e.a).a(((com.ss.android.article.browser.view.multiselect.viewholder.c) v0)).a(((f) this)).a(((com.ss.android.article.browser.view.multiselect.d) this)).a();
        this.c.setAdapter(this.d);
        this.c.setLayoutManager(new LinearLayoutManager(this.getContext()));
        return this.a;
    }

    public final void onDestroy() {
        super.onDestroy();
        FragmentActivity v0 = this.getActivity();
        if ((v0 instanceof UserActionHistoryActivity)) {
            com.ss.android.article.browser.download.aa v0_1 = ((UserActionHistoryActivity) v0).a;
            if (v0_1 != null) {
                v0_1.b = null;
            }
        }
    }

    public final void onDetach() {
        super.onDetach();
        this.f = null;
    }

    public final void onItemClick(AdapterView arg1, View arg2, int arg3, long arg4) {
    }
}

